<template>
  <div class="rightScreen">
    <div class="entScreen">
      <div class="title">
        <img :src="leftIcon" alt="" />
        <span>设备数量</span>
        <img :src="rightIcon" alt="" />
      </div>
      <div class="content chart">
        <PEcharts :option="deviceOption" />
      </div>
    </div>
    <div class="entScreen">
      <div class="title">
        <img :src="leftIcon" alt="" />
        <span>人员数量</span>
        <img :src="rightIcon" alt="" />
      </div>
      <div class="content chart">
        <PEcharts :option="personOption" />
      </div>
    </div>
    <div class="entScreen">
      <div class="title">
        <img :src="leftIcon" alt="" />
        <span>工艺执行率</span>
        <img :src="rightIcon" alt="" />
      </div>
      <div class="content chart">
        <PEcharts :option="pieOption" />
      </div>
    </div>
  </div>
</template>

<script>
import leftIcon from "@/assets/img/leftIcon.png";
import rightIcon from "@/assets/img/rightIcon.png";
import { deviceCharts, pieCharts } from "@/api/enterpriserSre";
import PEcharts from "@/components/charts/pEcharts";
export default {
  components: { PEcharts },
  data() {
    return {
      leftIcon: leftIcon,
      rightIcon: rightIcon,
      weldsOption: {},
      deviceOption: {},
      personOption: {},
      pieOption: {},
    };
  },
  computed: {
    spaceId() {
      return this.$store.getters.entSpaceId;
    },
  },

  mounted() {
    this.deviceCharts();
    this.pieCharts();
  },
  methods: {
    deviceCharts() {
      let params = {
        d: {
          c: [
            {
              key: "entSpaceId",
              value: this.spaceId,
            },
          ],
        },
      };
      deviceCharts(params).then((res) => {
        this.personOption = this.chartsinit(
          {
            color: ["#F45E23"],
          },
          res.result.user
        );
        this.deviceOption = this.chartsinit(
          {
            color: ["#0282DE"],
          },
          res.result.device
        );
      });
    },

    pieCharts() {
      let params = {
        d: {
          filters: [
            {
              field: "entSpaceId",
              operator: "equals",
              value: this.spaceId,
            },
          ],
        },
      };
      pieCharts(params).then((res) => {
        this.pieOption = {
          color: ["#0282DE", "#F21B62"],
          tooltip: {
            trigger: "item",
            formatter: "{b}: {c} ({d}%)",
          },
          legend: {
            data: ["正常", "异常"],
            textStyle: {
              color: "#fff",
            },
          },
          series: [
            {
              name: "访问来源",
              type: "pie",
              radius: ["40%", "55%"],
              avoidLabelOverlap: false,
              data: res.result.data,
            },
          ],
        };
      });
    },
    chartsinit(obj, data) {
      let option = {
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
            },
            data: data.xAxis.map((v) => ({
              value: v,
              textStyle: { color: "transparent" },
            })),
          },
        ],
        yAxis: {
          type: "value",
          axisLine: {
            show: false,
            lineStyle: {
              color: "rgba(255, 255, 255, 0.7)",
            },
          },
          splitLine: {
            show: false,
            lineStyle: {
              type: "dashed",
              color: "rgba(255, 255, 255, 0.7)",
            },
          },
        },
        tooltip: {
          show: true,
        },
        series: [
          {
            data: data.yAxis,
            type: "line",
            smooth: true,
          },
        ],
      };
      return Object.assign({}, option, obj);
    },
  },
};
</script>

<style lang="scss" scoped>
.rightScreen {
  position: absolute;
  right: 30px;
  top: 80px;
  .chart {
    height: 280px;
  }
}

.dangerB {
  background: #f90032;
}
.dangerF {
  color: #f90032;
}

.warningB {
  background: #f7c581;
}
.warningF {
  color: #f7c581;
}

.offB {
  background: #a5a3a0;
}
.offF {
  color: #a5a3a0;
}
</style>